package birs.controller.staff;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import birs.controller.staff.task.STF001Task;
import birs.util.ConnectionDB;

/**
 * Servlet implementation class FrmShowStaffByStaffTypeNow
 */
@WebServlet("/FrmShowStaffByStaffTypeNow")
public class STF001Controller extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public STF001Controller() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);   
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	private void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		// try-with-closable-resource java.sql.Connection, automatic close Connection when Task finished
		try (Connection misCon = ConnectionDB.getMisConnection()){
			STF001Task staffTypeTask = new STF001Task(misCon);
			if(request.getParameter("criteria") != null){
				staffTypeTask.getDrilldown(request, response);
			}else{
				staffTypeTask.getStaffType(request, response);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}